package day15;

public class TestObjectFactory {
	public static void main(String[] args) {
		Student s = (Student) ObjectFactory.getObject("day15.Student");
		s.show();
		Teacher t = (Teacher) ObjectFactory.getObject("day15.Teacher");
		t.show();
	}
}

class ObjectFactory {
	public static Object getObject(String className) {
		/*
		 * if(className.equals("Student")){ return new Student(); }else
		 * if(className.equals("Teacher")){ return new Teacher(); } return null;
		 */
		try {
			Class c = Class.forName(className);
			return c.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}

class Teacher {
	public void show(){
		System.out.println("Teacher.enclosing_method()");
	}
}
